package com.kerrykidz.system.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kerrykidz.common.Constants;
import com.kerrykidz.filemanagement.dao.mapper.LocPartyInoutEntityMapper;
import com.kerrykidz.parreserve.dao.mapper.ParReserveEntityMapper;
import com.kerrykidz.parreserve.dao.model.ParReserveEntity;
import com.kerrykidz.system.dao.mapper.GblSecBranEntityMapper;
import com.kerrykidz.system.dao.mapper.SysBarCodeEntityMapper;
import com.kerrykidz.system.dao.model.GblSecBranEntity;
import com.kerrykidz.system.dao.model.SysBarCodeEntity;
import com.kerrykidz.system.service.ISysBarCodeService;
import com.rdp.framework.exception.RDPException;
@Service
public class SysBarCodeServiceImpl implements ISysBarCodeService{
	@Autowired
	private SysBarCodeEntityMapper sysBarCodeEntityMapper;
	@Autowired
	private GblSecBranEntityMapper secBranEntityMapper;
	@Autowired
	private ParReserveEntityMapper parReserveEntityMapper;
	@Autowired
	private LocPartyInoutEntityMapper locPartyInoutEntityMapper;
	@Override
	public SysBarCodeEntity findBarCodeList(SysBarCodeEntity entity)
			throws RDPException {
		entity.setIspaging(true);
		List<SysBarCodeEntity> beanList = sysBarCodeEntityMapper.select(entity);
		if(beanList.size() > 0)
		{
			entity.setResults(beanList);
		}
		return entity;
	}
	@Override
	public void deleteBcode(SysBarCodeEntity entity) throws RDPException {
		sysBarCodeEntityMapper.deleteBcode(entity);
		
	}
	
	public void saveBatch(Map<String, Object> map) {
		sysBarCodeEntityMapper.saveBatch(map);
		
	}

	public void updateBcodeStatus(SysBarCodeEntity barCodeEntity) {
		sysBarCodeEntityMapper.updateBcodeStatus(barCodeEntity);
		
	}
	@Override
	public SysBarCodeEntity selectMaxSBarCode() {
		return sysBarCodeEntityMapper.selectMaxSBarCode();
	}
	@Override
	public List<GblSecBranEntity> selectBranList(String branId)
			throws RDPException {
		List<GblSecBranEntity> list = secBranEntityMapper.selectBranList(branId);
		return list;
	}
	@Override
	public void updateBcodeStatusBatch(Map<String, Object> map) {
		sysBarCodeEntityMapper.updateBcodeStatusBatch(map);
		String type=map.get("type").toString();// "initBcode" 类型 表示  预约管理 页面  初始化 条码，状态设置为占用
		if(!"initBcode".equals(type)){
			//更新状态为进行中
			String pkParresId=map.get("pkParresId").toString();
			ParReserveEntity parReserve = new ParReserveEntity();
			parReserve.setPkParresId(pkParresId);
			parReserve=parReserveEntityMapper.findParReserveById(parReserve);
			
			if(null!=type && "1".equals(type)){
				//进场操作(第一个进去的时候就为进行中)
				if(!Constants.RESERVE_STATUS_PROCEEDING.equals(parReserve.getResStatus())){
					parReserve.setResStatus(Constants.RESERVE_STATUS_PROCEEDING);
					parReserveEntityMapper.updateParReserve(parReserve);
				}
			}else{
				//出场操作(最后一个出场的时候改为完成)(已在页面控制)
				parReserve.setResStatus(Constants.RESERVE_STATUS_FINISH);
				parReserveEntityMapper.updateParReserve(parReserve);
			}
		}
	}
	@Override
	public List<SysBarCodeEntity> selectBarCodeList(SysBarCodeEntity entity)
			throws RDPException {
		
		return sysBarCodeEntityMapper.select(entity);
	}
	@Override
	public SysBarCodeEntity selectBarCode(SysBarCodeEntity entity)
			throws RDPException {
		
		return sysBarCodeEntityMapper.selectBarCode(entity);
	}
	@Override
	public List<String> findProcessInOut(String[] bcodeId) {
		HashMap<String,Object> sysCodeMap =new HashMap<String,Object>();
		sysCodeMap.put("sysCodeList", bcodeId);
		return locPartyInoutEntityMapper.findProcessInOut(sysCodeMap);
	}
	
	
}
